home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2000 March / maximum-cd-2000-03.iso / Quake3 Game Source / Q3AGameSource.exe / Main / ui_menu.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-01-18  |  7.1 KB  |  290 lines

  1. // Copyright (C) 1999-2000 Id Software, Inc.
  2. //
  3. /*
  4. =======================================================================
  5.  
  6. MAIN MENU
  7.  
  8. =======================================================================
  9. */
  10.  
  11.  
  12. #include "ui_local.h"
  13.  
  14.  
  15. #define ID_SINGLEPLAYER            10
  16. #define ID_MULTIPLAYER            11
  17. #define ID_SETUP                12
  18. #define ID_DEMOS                13
  19. #define ID_CINEMATICS            14
  20. #define ID_EXIT                    15
  21.  
  22. #define MAIN_BANNER_MODEL                "models/mapobjects/banner/banner5.md3"
  23. #define MAIN_MENU_VERTICAL_SPACING        34
  24.  
  25.  
  26. typedef struct {
  27.     menuframework_s    menu;
  28.  
  29.     menutext_s        singleplayer;
  30.     menutext_s        multiplayer;
  31.     menutext_s        setup;
  32.     menutext_s        demos;
  33.     menutext_s        cinematics;
  34.     menutext_s        exit;
  35.  
  36.     qhandle_t        bannerModel;
  37. } mainmenu_t;
  38.  
  39.  
  40. static mainmenu_t s_main;
  41.  
  42.  
  43. /*
  44. =================
  45. MainMenu_ExitAction
  46. =================
  47. */
  48. static void MainMenu_ExitAction( qboolean result ) {
  49.     if( !result ) {
  50.         return;
  51.     }
  52.     UI_PopMenu();
  53.     UI_CreditMenu();
  54. }
  55.  
  56.  
  57. /*
  58. =================
  59. Main_MenuEvent
  60. =================
  61. */
  62. void Main_MenuEvent (void* ptr, int event) {
  63.     if( event != QM_ACTIVATED ) {
  64.         return;
  65.     }
  66.  
  67.     switch( ((menucommon_s*)ptr)->id ) {
  68.     case ID_SINGLEPLAYER:
  69.         UI_SPLevelMenu();
  70.         break;
  71.  
  72.     case ID_MULTIPLAYER:
  73.         UI_ArenaServersMenu();
  74.         break;
  75.  
  76.     case ID_SETUP:
  77.         UI_SetupMenu();
  78.         break;
  79.  
  80.     case ID_DEMOS:
  81.         UI_DemosMenu();
  82.         break;
  83.  
  84.     case ID_CINEMATICS:
  85.         UI_CinematicsMenu();
  86.         break;
  87.  
  88.     case ID_EXIT:
  89.         UI_ConfirmMenu( "EXIT GAME?", NULL, MainMenu_ExitAction );
  90.         break;
  91.     }
  92. }
  93.  
  94.  
  95. /*
  96. ===============
  97. MainMenu_Cache
  98. ===============
  99. */
  100. void MainMenu_Cache( void ) {
  101.     s_main.bannerModel = trap_R_RegisterModel( MAIN_BANNER_MODEL );
  102. }
  103.  
  104.  
  105. /*
  106. ===============
  107. Main_MenuDraw
  108. ===============
  109. */
  110. static void Main_MenuDraw( void ) {
  111.     refdef_t        refdef;
  112.     refEntity_t        ent;
  113.     vec3_t            origin;
  114.     vec3_t            angles;
  115.     float            adjust;
  116.     float            x, y, w, h;
  117.     vec4_t            color = {0.5, 0, 0, 1};
  118.  
  119.     // setup the refdef
  120.  
  121.     memset( &refdef, 0, sizeof( refdef ) );
  122.  
  123.     refdef.rdflags = RDF_NOWORLDMODEL;
  124.  
  125.     AxisClear( refdef.viewaxis );
  126.  
  127.     x = 0;
  128.     y = 0;
  129.     w = 640;
  130.     h = 120;
  131.     UI_AdjustFrom640( &x, &y, &w, &h );
  132.     refdef.x = x;
  133.     refdef.y = y;
  134.     refdef.width = w;
  135.     refdef.height = h;
  136.  
  137.     adjust = 0; // JDC: Kenneth asked me to stop this 1.0 * sin( (float)uis.realtime / 1000 );
  138.     refdef.fov_x = 60 + adjust;
  139.     refdef.fov_y = 19.6875 + adjust;
  140.  
  141.     refdef.time = uis.realtime;
  142.  
  143.     origin[0] = 300;
  144.     origin[1] = 0;
  145.     origin[2] = -32;
  146.  
  147.     trap_R_ClearScene();
  148.  
  149.     // add the model
  150.  
  151.     memset( &ent, 0, sizeof(ent) );
  152.  
  153.     adjust = 5.0 * sin( (float)uis.realtime / 5000 );
  154.     VectorSet( angles, 0, 180 + adjust, 0 );
  155.     AnglesToAxis( angles, ent.axis );
  156.     ent.hModel = s_main.bannerModel;
  157.     VectorCopy( origin, ent.origin );
  158.     VectorCopy( origin, ent.lightingOrigin );
  159.     ent.renderfx = RF_LIGHTING_ORIGIN | RF_NOSHADOW;
  160.     VectorCopy( ent.origin, ent.oldorigin );
  161.  
  162.     trap_R_AddRefEntityToScene( &ent );
  163.  
  164.     trap_R_RenderScene( &refdef );
  165.  
  166.     // standard menu drawing
  167.  
  168.     Menu_Draw( &s_main.menu );
  169.  
  170.     if (uis.demoversion) {
  171.         UI_DrawProportionalString( 320, 372, "DEMO      FOR MATURE AUDIENCES      DEMO", UI_CENTER|UI_SMALLFONT, color );
  172.         UI_DrawString( 320, 400, "Quake III Arena(c) 1999, Id Software, Inc.  All Rights Reserved", UI_CENTER|UI_SMALLFONT, color );
  173.     } else {
  174.         UI_DrawString( 320, 450, "Quake III Arena(c) 1999, Id Software, Inc.  All Rights Reserved", UI_CENTER|UI_SMALLFONT, color );
  175.     }
  176. }
  177.  
  178.  
  179. /*
  180. ===============
  181. UI_MainMenu
  182.  
  183. The main menu only comes up when not in a game,
  184. so make sure that the attract loop server is down
  185. and that local cinematics are killed
  186. ===============
  187. */
  188. void UI_MainMenu( void ) {
  189.     int        y;
  190.     int        style = UI_CENTER | UI_DROPSHADOW;
  191.  
  192.     trap_Cvar_Set( "sv_killserver", "1" );
  193.  
  194.     if( !uis.demoversion && !ui_cdkeychecked.integer ) {
  195.         char    key[17];
  196.  
  197.         trap_GetCDKey( key, sizeof(key) );
  198.         if( strcmp( key, "123456789" ) == 0 ) {
  199.             UI_CDKeyMenu();
  200.             return;
  201.         }
  202.     }
  203.  
  204.     memset( &s_main, 0 ,sizeof(mainmenu_t) );
  205.  
  206.     MainMenu_Cache();
  207.  
  208.     s_main.menu.draw = Main_MenuDraw;
  209.     s_main.menu.fullscreen = qtrue;
  210.     s_main.menu.wrapAround = qtrue;
  211.     s_main.menu.showlogo = qtrue;
  212.  
  213.     y = 134;
  214.     s_main.singleplayer.generic.type        = MTYPE_PTEXT;
  215.     s_main.singleplayer.generic.flags        = QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
  216.     s_main.singleplayer.generic.x            = 320;
  217.     s_main.singleplayer.generic.y            = y;
  218.     s_main.singleplayer.generic.id            = ID_SINGLEPLAYER;
  219.     s_main.singleplayer.generic.callback    = Main_MenuEvent; 
  220.     s_main.singleplayer.string                = "SINGLE PLAYER";
  221.     s_main.singleplayer.color                = color_red;
  222.     s_main.singleplayer.style                = style;
  223.  
  224.     y += MAIN_MENU_VERTICAL_SPACING;
  225.     s_main.multiplayer.generic.type            = MTYPE_PTEXT;
  226.     s_main.multiplayer.generic.flags        = QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
  227.     s_main.multiplayer.generic.x            = 320;
  228.     s_main.multiplayer.generic.y            = y;
  229.     s_main.multiplayer.generic.id            = ID_MULTIPLAYER;
  230.     s_main.multiplayer.generic.callback        = Main_MenuEvent; 
  231.     s_main.multiplayer.string                = "MULTIPLAYER";
  232.     s_main.multiplayer.color                = color_red;
  233.     s_main.multiplayer.style                = style;
  234.  
  235.     y += MAIN_MENU_VERTICAL_SPACING;
  236.     s_main.setup.generic.type                = MTYPE_PTEXT;
  237.     s_main.setup.generic.flags                = QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
  238.     s_main.setup.generic.x                    = 320;
  239.     s_main.setup.generic.y                    = y;
  240.     s_main.setup.generic.id                    = ID_SETUP;
  241.     s_main.setup.generic.callback            = Main_MenuEvent; 
  242.     s_main.setup.string                        = "SETUP";
  243.     s_main.setup.color                        = color_red;
  244.     s_main.setup.style                        = style;
  245.  
  246.     y += MAIN_MENU_VERTICAL_SPACING;
  247.     s_main.demos.generic.type                = MTYPE_PTEXT;
  248.     s_main.demos.generic.flags                = QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
  249.     s_main.demos.generic.x                    = 320;
  250.     s_main.demos.generic.y                    = y;
  251.     s_main.demos.generic.id                    = ID_DEMOS;
  252.     s_main.demos.generic.callback            = Main_MenuEvent; 
  253.     s_main.demos.string                        = "DEMOS";
  254.     s_main.demos.color                        = color_red;
  255.     s_main.demos.style                        = style;
  256.  
  257.     y += MAIN_MENU_VERTICAL_SPACING;
  258.     s_main.cinematics.generic.type            = MTYPE_PTEXT;
  259.     s_main.cinematics.generic.flags            = QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
  260.     s_main.cinematics.generic.x                = 320;
  261.     s_main.cinematics.generic.y                = y;
  262.     s_main.cinematics.generic.id            = ID_CINEMATICS;
  263.     s_main.cinematics.generic.callback        = Main_MenuEvent; 
  264.     s_main.cinematics.string                = "CINEMATICS";
  265.     s_main.cinematics.color                    = color_red;
  266.     s_main.cinematics.style                    = style;
  267.  
  268.     y += MAIN_MENU_VERTICAL_SPACING;
  269.     s_main.exit.generic.type                = MTYPE_PTEXT;
  270.     s_main.exit.generic.flags                = QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
  271.     s_main.exit.generic.x                    = 320;
  272.     s_main.exit.generic.y                    = y;
  273.     s_main.exit.generic.id                    = ID_EXIT;
  274.     s_main.exit.generic.callback            = Main_MenuEvent; 
  275.     s_main.exit.string                        = "EXIT";
  276.     s_main.exit.color                        = color_red;
  277.     s_main.exit.style                        = style;
  278.  
  279.     Menu_AddItem( &s_main.menu,    &s_main.singleplayer );
  280.     Menu_AddItem( &s_main.menu,    &s_main.multiplayer );
  281.     Menu_AddItem( &s_main.menu,    &s_main.setup );
  282.     Menu_AddItem( &s_main.menu,    &s_main.demos );
  283.     Menu_AddItem( &s_main.menu,    &s_main.cinematics );
  284.     Menu_AddItem( &s_main.menu,    &s_main.exit );             
  285.  
  286.     trap_Key_SetCatcher( KEYCATCH_UI );
  287.     uis.menusp = 0;
  288.     UI_PushMenu ( &s_main.menu );
  289. }
  290.